﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using MINERP.COM;

namespace MINERP.DAL.Statistics
{
    public  class BillCheckDAL:DALBase
    {
        public void CheckErrBill()
        {
           List<SHOP_Bill> listShopBill= DataEntites.SHOP_Bill.ToList();
           foreach (SHOP_Bill shopBill in listShopBill)
           {
               shopBill.Bill_Detail.Load();
               shopBill.ShopReference.Load();
               List<Bill_Detail> listDetail = shopBill.Bill_Detail.ToList();
               foreach (Bill_Detail detail in listDetail)
               {
                   int shopid = GetProductByBarCode(detail.OrderInfoCode);
                   if (shopBill.Shop.ShopId != shopid)
                   {
                       //Console.WriteLine(shopBill.Shop.ShopId + "||" + detail.OrderInfoCode);
                       WriteLogForCheck.WriteLogFile(shopBill.BillId+"||" +shopBill.Shop.ShopId + "||" + detail.OrderInfoCode+"||"+shopid);
                   }

               }

           }
        }
        public int GetProductByBarCode(string inBarCode)
        {
          orderInfo oi=   DataEntites.orderInfo.Where(p => p.OrderProductCode == inBarCode).FirstOrDefault();
          oi.Tb_OrderBagReference.Load();
          Tb_OrderBag orderBag = oi.Tb_OrderBag;
          orderBag.ShopReference.Load();
          return orderBag.Shop.ShopId;
        }
    }
}
